import drinks.Coffee;
import drinksFactory.AmericanoFactory;
import drinksFactory.CappuccinoFactory;
import drinksFactory.CoffeeFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class CoffeeShop {
    private final Map<String, CoffeeFactory> factories = new HashMap<>();

    public CoffeeShop() {
        registerCoffeeType("americano", new AmericanoFactory());
        registerCoffeeType("cappuccino", new CappuccinoFactory());
    }

    public void registerCoffeeType(String type, CoffeeFactory factory) {
        factories.put(type.toLowerCase(), factory);
    }//ai认为，为了实现开闭原则，新增咖啡类型时（如 Latte），除了添加对应的 Coffee 实现和 CoffeeFactory 实现类外，还应该通过 registerCoffeeType 注册，此时无需修改现有代码。

    public void orderCoffee(String type) {
        CoffeeFactory factory = factories.get(type.toLowerCase());
        if (factory == null) {
            throw new IllegalArgumentException("不支持的咖啡类型: " + type);
        }
        Coffee coffee = factory.createCoffee();
        coffee.brew();
        CondimentAdder.addDefaultCondiments();
    }

    public static void main(String[] args) {
        CoffeeShop shop = new CoffeeShop();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您想要的咖啡类型(americano/cappuccino): ");
        String coffeeType = scanner.nextLine();

        try {
            shop.orderCoffee(coffeeType);
        } catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
        }

        scanner.close();

    }
}